package test.demo;


import org.apache.log4j.BasicConfigurator;


import org.apache.log4j.Level;
import org.apache.log4j.Logger;



import cop.publ.Ctx;
import cop.publ.LayeredClass;

@LayeredClass
public class Person {

	static{BasicConfigurator.configure();}
	private static final Logger logger = Logger.getLogger(Person.class);
	static{ logger.setLevel(Level.ALL); }  

	public static int count = Performance.DEPTH;
	

	

	public String printALayer(String s){
		logger.debug("print layer A");
		String r = print(s);
		Performance.fact();
		logger.debug("print layer A");
		return "A" + r;
	}

	public String printBLayer(String s){
		logger.debug("print layer B");
		String r = print(s);
		Performance.fact();
		logger.debug("print layer B");
		return "B" + r;
	}


	public String printCLayer(String s){
		logger.debug("print layer C");
		String r = print(s);
		Performance.fact();
		logger.debug("print layer C");
		return "C" + r;
	}
	
	public String print(String s){
		logger.debug("print base method");
		String r = s;
		//if (count > 0) {
			//count--;
			//Performance.fact();
			//r = print(s);
		//}
		return r;
	}
	
	public String print2(int a){
		System.out.println("print2 base method: " + new Integer(a).toString());
		return "print base method";
	}
	
	
	
	/**
	 * @param args
	 */
	public static void main(String[] args) {
		
		Person p = new Person();
		
		logger.debug("start");
		
		Ctx.withActiveLayer(C.id);
		Ctx.withActiveLayer(B.id);
		Ctx.withActiveLayer(A.id);
		
		//p.print("INIT");
		
		count = Performance.DEPTH;
		int tmp1 = count;
		
		int loop = Performance.LOOP;
		int tmp2 = loop;
		
		String out = "";
		long time1 = System.currentTimeMillis();
		while(loop > 0 ){
			out = p.print("INIT");
			loop--;
		}
		long time2 = System.currentTimeMillis();
		
		
		int tmp3 = Performance.FACT;
		
		System.out.println(out);
		System.out.format("%d %d %d : %d%n",tmp1, tmp2, tmp3, time2-time1);
		
		
		Ctx.end();
		Ctx.end();
		Ctx.end();

			
	}
}





